package com.bridge.common.intercepters;

import com.bridge.common.base.BaseAppLication;

import java.io.File;
import java.io.IOException;
import okhttp3.Interceptor;
import okhttp3.Response;

/**
 * @author Houwq
 * created on 2018年12月29日 17:50
 * desc
 **/
public class DeleteFilesIntercepter implements Interceptor{
    @Override
    public Response intercept(Chain chain) throws IOException {
        Response response = chain.proceed(chain.request());
        deleteFilesByDirectory(BaseAppLication.getContext().getCacheDir());
        return response;
    }

    private static void deleteFilesByDirectory(File directory) {
        if (directory != null && directory.exists() && directory.isDirectory()) {
            for (File item : directory.listFiles()) {
                item.delete();
            }
        }
    }
}
